/**
 * 详情对话框
 */
var FactoryVideoInfoDlg = {
    data: {
        factoryId: "",
        title: "",
        description: "",
        url: "",
        image: "",
        status: "",
        weigh: "",
        createTime: "",
        updateTime: "",
        recordStatus: ""
    },
    editor:null,
};

layui.use(['form', 'admin', 'ax','simTool','laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var simtool = layui.simTool;
    var laydate = layui.laydate;

    //让当前iframe弹层高度适应
    //admin.iframeAuto();
    //页面渲染
    var E = window.wangEditor;
    var editor = new E('#description_toolbar', '#description_text');
    // 将图片大小限制为 2M
    editor.customConfig.uploadImgMaxSize = 50* 1024 * 1024;
    editor.customConfig.uploadImgServer =Feng.ctxPath+'/upload/wang'; //'common/batch/imgUpdate';
    editor.customConfig.uploadFileName = 'file';
    editor.customConfig.customAlert = function (info){
        // info 是需要提示的内容
        alert('上传失败，请重试：' + info);
    }
    editor.create();
    FactoryVideoInfoDlg.editor = editor;



    /**
     * 图片上传
     * @type {simtool}
     */
    var sim = new simtool("/upload","#picBox");
    sim.uploadImg()
    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/factoryVideo/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('factoryVideoForm', result.data);
    //渲染
    Feng.buttonInit("status",result.data.status);
    $("#picBox").find("img").attr("src",Feng.ctxPath+result.data.image)
    FactoryVideoInfoDlg.editor.txt.html(result.data.description)
    form.render()
    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/factoryVideo/editItem", function (data) {
            Feng.success("更新成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set("image",$("#picBox").find("input").val())
        ajax.set("status",$("#status").attr("checked")=="checked"?1:0);
        ajax.set("description",editor.txt.html())
        ajax.set(data.field);
        ajax.start();
    });
});